package com.wz.project.bas.workshopClass.controller;

import com.wz.framework.aspectj.lang.annotation.Log;
import com.wz.framework.aspectj.lang.enums.BusinessType;
import com.wz.framework.web.controller.BaseController;
import com.wz.framework.web.domain.AjaxResult;
import com.wz.project.bas.workshopClass.domain.BasWorkshopClass;
import com.wz.project.bas.workshopClass.service.WorkshopClassService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Controller
@RequestMapping("/bas/workshopclass")
public class WorkshopClassController extends BaseController {

    private String prefix = "bas/workshopclass";

    @Autowired
    WorkshopClassService workshopClassService;

    @RequiresPermissions("bas:workshopclass:view")
    @GetMapping()
    public String user()
    {
        return prefix + "/workshopclass";
    }

    @PostMapping("/list")
    @ResponseBody
    public Object getList(BasWorkshopClass basWorkshopClass){

        startPage();
        List<BasWorkshopClass> list=workshopClassService.selectWorkshopClassList(basWorkshopClass);
        System.out.println(list);
        return getDataTable(list);
    }

    @Log(title = "项目管理", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody

    public AjaxResult remove(String ids)
    {

        return toAjax(workshopClassService.deleteWorkshopClassByIds(ids));
    }

    /**
     * 修改项目
     * @param id
     * @param mmap
     * @return
     */
    @RequiresPermissions("bas:warehouse:edits")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        BasWorkshopClass basWorkshopClass=workshopClassService.selectWorkshopClassById(id);
//        List<Prjgroup> prjgroups = prjGroupService.selectPrjgroupByDeptId(basWarehouse.getWarehouse_id());
        mmap.put("basWorkshopClass", basWorkshopClass);
//        mmap.put("prjgroups",prjgroups);
        return prefix + "/edit";
    }

    /**
     * 修改保存用户
     */
    @RequiresPermissions("system:item:saveAndUpdate")
    @PostMapping("/saveAndUpdate")
    @ResponseBody
    public AjaxResult saveAndUpdate(@Validated BasWorkshopClass basWorkshopClass)
    {

        return toAjax(workshopClassService.saveAndUpdate(basWorkshopClass));
    }

    /**
     * 新增项目
     */
    @GetMapping("/add")
    public String add(ModelMap mmap)
    {
        /*mmap.put("roles", roleService.selectRoleAll().stream().filter(r -> !r.isAdmin()).collect(Collectors.toList()));
        mmap.put("posts", postService.selectPostAll());*/
        return prefix + "/add";
    }

    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(BasWorkshopClass basWorkshopClass)
    {
//        item.setTheProblem("无");
        String s = String.valueOf(System.currentTimeMillis());
        String substring = s.substring(s.length() - 6);
//        int pejId = Integer.parseInt(substring);
        basWorkshopClass.setId(substring);
        return toAjax(workshopClassService.insertWorkshopClass(basWorkshopClass));
    }


}
